/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bs.stock.web;

import bs.stock.modelo.Deposito;
import bs.stock.rn.DepositoRN;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

/**
 *
 * @author Claudio
 */
@ManagedBean(name="buscadorDepositoBean")
@SessionScoped
public class BuscadorDepositoBean {

    @EJB private DepositoRN depositoRN;

    private Deposito deposito;
    private List<Deposito> lista;
    
    public BuscadorDepositoBean() {

    }

    @PostConstruct
    public void init(){
        deposito = new Deposito();
        lista = depositoRN.getLista("N");
    }

    public List<Deposito> completeCodigoDeposito(String query) {
        List<Deposito> suggestions = new ArrayList<Deposito>();

        for(Deposito p : lista) {
            if(p.getDescripcion().contains(query))
                suggestions.add(p);
        }
        return suggestions;
    }

    public List<Deposito> completeDescripcionProducto(String query) {
        List<Deposito> suggestions = new ArrayList<Deposito>();

        for(Deposito p : lista) {
            if(p.getDescripcion().contains(query))
                suggestions.add(p);
        }
        return suggestions;  
        
//        <p:autoComplete value="#{autoCompleteBean.selectedPlayer1}" id="basicPojo" completeMethod="#{autoCompleteBean.completePlayer}"  
//                        var="p" itemLabel="#{p.name}" itemValue="#{p}" converter="player" forceSelection="true"/>
    }

    public void seleccionar(Deposito d){
        deposito = d;
    }

    public Deposito getDeposito() {
        return deposito;
    }

    public void setDeposito(Deposito deposito) {
        this.deposito = deposito;
    }

    public List<Deposito> getLista() {
        return lista;
    }

    public void setLista(List<Deposito> lista) {
        this.lista = lista;
    }

}
